package com.lxp.eduService.controller;


import com.lxp.eduService.domain.EduChapter;
import com.lxp.eduService.domain.vo.CourseInfo;
import com.lxp.eduService.domain.vo.chapter.ChapterVo;
import com.lxp.eduService.service.impl.EduChapterServiceImpl;
import com.lxp.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author lxp
 * @since 2021-11-20
 */
//章节控制层
@RestController
@RequestMapping("/eduService/edu-chapter")
public class EduChapterController {
    @Autowired
    private EduChapterServiceImpl eduChapterService;

    //根据课程id 查询出章节 以及小节
    @GetMapping("/getChapterVideo/{courseID}")
    public R getChapterVideo(@PathVariable String courseID){

        List<ChapterVo> list =eduChapterService.getChapterVideo(courseID);
        return R.ok().data("list",list);
    }


    //添加章节
    @PostMapping("/addChapter")
    public R addChapter(@RequestBody EduChapter eduChapter){
        boolean flag=eduChapterService.save(eduChapter);
        if (flag){
            return R.ok();
        }
        return R.error().message("网络异常");
    }

    //根据id查询章节
    @GetMapping("/selectChapterById/{chapterId}")
    public R selectChapterById(@PathVariable String chapterId){
        EduChapter eduChapter = eduChapterService.getById(chapterId);
        return R.ok().data("eduChapter",eduChapter);
    }

    //根据id修改章节
    @PostMapping("/updateChapterById")
    public R updateChapterById(@RequestBody EduChapter eduChapter){
        boolean flag=eduChapterService.updateById(eduChapter);
        if (flag){
            return R.ok();
        }
        return R.error().message("网络异常");
    }

    //根据id 删除章节(没存在小节的时候才可以删除)
    //根据id查询章节
    @GetMapping("/deleteChapterById/{chapterId}")
    public R deleteChapterById(@PathVariable String chapterId){
       boolean flag=eduChapterService.deleteById(chapterId);
       if (flag){
           return R.ok();
       }
       return R.error().message("网络异常");
    }
}

